package org.atlantis.datasink.cfg;

import java.util.HashMap;
import java.util.Map;

import org.atlantis.datasink.server.ServerOption;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

class ServerOptionFragment extends AbstractOptionFragment<ServerOption> {

	@Override
	public ServerOption parse(Element optElm) throws Exception {
		ServerOptionImpl servOpt = new ServerOptionImpl();
		servOpt.name = optElm.getAttribute(NAME_ATTR);
		NodeList extendsList = optElm.getElementsByTagName(EXTENDS_TAG);
		if (extendsList.getLength() > 0) servOpt.extendMap = parseExtend((Element) extendsList.item(0));
		return servOpt;
	}

	private static class ServerOptionImpl implements ServerOption {

		Map<String, String> extendMap = new HashMap<String, String>();
		String name;

		@Override
		public String getExtend(String key) {
			return extendMap.get(key);
		}

		@Override
		public String getName() {
			return name;
		}
	}
}
